#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *table1;
    GtkWidget *table2;
    GtkWidget *entry1;
    GtkWidget *entry2;
    GtkWidget *entry3;
    GtkWidget *entry4;
    GtkWidget *button1;
    GtkWidget *button2;
    GtkWidget *label1;
    GtkWidget *label2;
    GtkWidget *label3;
    GtkWidget *label4;
    GtkWidget *label5;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "用户信息");
    //定义一个3行2列的表格，单元格大小会根据单元格中的元件大小自动调整
    table1 = gtk_table_new(4, 4, FALSE);
    //定义一个1行2列的表格2，单元格大小会根据单元格中的元件大小自动调整
    table2 = gtk_table_new(1, 2, FALSE);
    //下面是分别定义5个标签，2个按钮，4个文本框
    label1 = gtk_label_new("我的信息");
    label2 = gtk_label_new("用户名");
    label3 = gtk_label_new("密码");
    label4 = gtk_label_new("电子邮件");
    label5 = gtk_label_new("详细地址");
    button1 = gtk_button_new_with_label("注册");
    button2 = gtk_button_new_with_label("登录");
    entry1 = gtk_entry_new();
    entry2 = gtk_entry_new();
    entry3 = gtk_entry_new();
    entry4 = gtk_entry_new();

    gtk_container_add(GTK_CONTAINER(window), table1); //将表格添加到窗口中
    //下面是5个元件分别添加到表格相应的位置中
    gtk_table_attach(GTK_TABLE(table1), label1, 0, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), label2, 3, 4, 0, 1, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), label2, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), entry1, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), label3, 2, 3, 1, 2, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), entry2, 3, 4, 1, 2, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), label4, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), entry3, 1, 4, 2, 3, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), label5, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 5, 5);
    gtk_table_attach(GTK_TABLE(table1), entry4, 1, 4, 3, 4, GTK_FILL, GTK_FILL, 5, 5);

    gtk_table_attach(GTK_TABLE(table2), button1, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 2, 5);
    gtk_table_attach(GTK_TABLE(table2), button2, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 2, 5);

    gtk_widget_show_all(window); //显示窗口中的所有远近
    gtk_main();
    return 0;
}